package com.ccb.jyzx.expand.tiantouonline.controller;

import com.ccb.jyzx.expand.tiantouonline.view.response.ActionEntity;
import com.ccb.jyzx.expand.tiantouonline.view.response.Permission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author XIEFEI
 * @date 2019-11-20 12:57
 * @Description 用户信息接口
 **/
@Controller
@RequestMapping("/tto/user")
@Api(tags = {"用户信息操作接口"})
public class UserInfoController {
    @ApiOperation(value = "获取用户信息", notes = "获取用户信息")
    @ApiResponses({
            @ApiResponse(code = 200, message = "请求成功"),
            @ApiResponse(code = 400, message = "错误的请求,服务器无法解析或缺少必填参数"),
            @ApiResponse(code = 401, message = "当前请求需要用户验证,或权限验证失败"),
            @ApiResponse(code = 404, message = "不存在的网络资源"),
            @ApiResponse(code = 500, message = "服务器发生异常")
    })
    @PostMapping(value ="getUseInfo")
    @ResponseBody
    public Map<String,Object> getUserinfo(){

        Map<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("message","");
        map.put("timestamp",System.currentTimeMillis());

        Map<String,Object> result= new HashMap<>();
        result.put("avatar","/avatar2.jpg");//头像地址
        result.put("name","管理员");//用户中文名
        result.put("password","");//用户密码
        result.put("username","admin");//用户名/用户账号


        //角色及权限
        Map<String,Object> role= new HashMap<>();
        result.put("createTime",1497160610259L);//角色创建时间
        result.put("creatorId","system");//角色创建者ID
        result.put("deleted",0);//是否删除 0 否 1 是
        result.put("describe","拥有所有权限");//角色描述
        result.put("id","admin");//角色ID
        result.put("name","超级管理员");//角色中文名


        Permission p0 = new Permission();
        ArrayList<Permission> permissions= new ArrayList<>();
        ArrayList<ActionEntity> actionEntitieSet= new ArrayList<>();

        ActionEntity add = new ActionEntity();
        add.setAction("add");
//        add.setDescribe("新增");

        ActionEntity query = new ActionEntity();
        add.setAction("query");
//        add.setDescribe("查询");

        ActionEntity get = new ActionEntity();
        add.setAction("get");
//        add.setDescribe("详情");

        ActionEntity update = new ActionEntity();
        add.setAction("update");
//        add.setDescribe("修改");

        ActionEntity delete = new ActionEntity();
        add.setAction("delete");
//        add.setDescribe("删除");

        actionEntitieSet.add(0,add);
        actionEntitieSet.add(1,query);
        actionEntitieSet.add(2,get);
        actionEntitieSet.add(3,update);
        actionEntitieSet.add(4,delete);

        p0.setActionEntitySet(actionEntitieSet);

        p0.setPermissionId("devTest");
        p0.setPermissionName("开发");

        permissions.add(0,p0);

        role.put("permissions",permissions);

        result.put("role",role);
        map.put("result",result);

//        System.out.println(JSON.toJSONString(map));
        return map;
    }

}
